package hzn.service.impl;

import bean.UserAddress;
import com.alibaba.dubbo.config.annotation.Reference;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import hzn.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import service.UserService;

@Service
public class OrderServiceImpl implements OrderService {
    //@Reference//dubbo注解
    @Reference(timeout=2000,retries=3)
    //@Reference(version = "*")
    //@Reference(stub="hzn.service.impl.UserServiceStub",url="192.168.4.27:20880")//此时的service是UserServiceStub
    //@Reference(loadbalance ="consistenthash" )
    UserService service;

    @HystrixCommand(fallbackMethod="abc")
    public UserAddress initOrder(String id) {
        UserAddress address=service.getUserAddress(id);
        System.out.println("用户的信息："+address);
        return address;
    }

    public UserAddress abc(String id){
        UserAddress address=new UserAddress(3,"天津","3","马云","145324","N");
        System.out.println("provider出错后，调用consumer提供的容错方法"+address);
        return address;
    }
}
